<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('发射机设置')"/>
</head>
<style>
	.layui-form-label {
		width: 100px !important;
		text-align: left !important;
	}

	.layui-form-item .layui-input-inline {
		width: 200px !important;
		margin-bottom: 0px !important;
	}

	.layui-form-item-te {
		margin-bottom: 0px !important;
	}
</style>
<body class="pear-container">

<div class="layui-col-md5">
	<div class="layui-card">
		<div class="layui-card-body">
			<div id="organizationTreeContent" style="height: 550px;overflow: auto;">
				<ul id="dataTree" class="dtree organizationTree" data-id="0" ></ul>
			</div>
		</div>
	</div>
</div>
<div class="layui-col-md7">
	<div class="layui-card">
		<div class="layui-card-body">
		<form class="layui-form layui-form-pane" action="" id="tranform"  lay-filter="tranform">
			<div class="layui-form-item layui-form-item-te" style="padding-left: 5%;padding-top: 5%;">
				<label class="layui-form-label" style="width: 7%">台站ID</label>
				<div class="layui-input-inline" style="width: 12%;margin-right: 100px;">
					<input type="text" class="layui-input" id="code" name="code" autocomplete="off">
				</div>
			</div>
			<div class="layui-form-item layui-form-item-te" style="padding-left: 5%;padding-top: 2%;">
				<label class="layui-form-label" style="width: 7%;">台站名称</label>
				<div class="layui-input-inline" style="width: 12%;margin-right: 100px;">
					<input type="text" class="layui-input" id="name" name="name" autocomplete="off" >
				</div>
			</div>
			<div class="layui-form-item layui-form-item-te" style="padding-left: 5%;padding-top: 2%;">
				<label class="layui-form-label" style="width: 7%">台站地址</label>
				<div class="layui-input-inline" style="width: 12%;margin-right: 100px;">
					<input type="text" class="layui-input" id="address" name="address" autocomplete="off" >
				</div>
			</div>
			<div class="layui-form-item layui-form-item-te" style="padding-left: 5%;padding-top: 2%;">
				<label class="layui-form-label" style="width: 7%">所属区域</label>
				<div class="layui-input-inline" style="width: 12%;margin-right: 100px;">
					<input type="text" class="layui-input" id="regionname" name="regionname" autocomplete="off" >
					<input type="hidden" class="layui-input" id="region" name="region" autocomplete="off" >
				</div>
			</div>
			<div class="layui-form-item layui-form-item-te" style="padding-left: 5%;padding-top: 2%;">
				<label class="layui-form-label" style="width: 7%">经度</label>
				<div class="layui-input-inline" style="width: 12%;margin-right: 100px;">
					<input type="text" class="layui-input" id="longitude" name="longitude" autocomplete="off" >
				</div>
			</div>
			<div class="layui-form-item layui-form-item-te" style="padding-left: 5%;padding-top: 2%;">
				<label class="layui-form-label" style="width: 7%">纬度</label>
				<div class="layui-input-inline" style="width: 12%;margin-right: 100px;">
					<input type="text" class="layui-input" id="latitude" name="latitude" autocomplete="off" >
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block" style="padding-top: 10%;">
					<button class="layui-btn" th:type="button" lay-filter="transmiterSet" onclick="transmiterSet()">
						添加
					</button>
					<button class="layui-btn" th:type="button" lay-filter="closeTransmiter" onclick="closeTransmiter()">
						关闭
					</button>
				</div>
			</div>
		</form>
		</div>
	</div>
</div>
</body>
<th:block th:include="include :: footer"/>
<script>
	layui.use(['table', 'form', 'popup', 'jquery', 'element', 'util','layer','dtree'], function () {
		let form = layui.form;
		let popup = layui.popup;
		let dtree = layui.dtree;
		let MODULE_PATH = "/system/station/";
		/**
		 * 终端系统信息设置模板(后续去除系统信息无需设置)
		 */
		window.transmiterSet = function () {
			var d = {};
			var t = $('#tranform').serializeArray();
			$.each(t, function() {
				d[this.name] = this.value;
			});
			$.ajax({
				url: MODULE_PATH + 'addStation',
				type: 'POST',
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(d),
				success: function (data) {
					if (data.code === 200) {
						popup.success(data.msg);
						window.parent.location.reload();
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					} else {
						popup.failure(data.msg);
					}
				},
				error: function () {
					popup.failure("添加台站接口访问失败!")
				}
			});
		}
		window.closeTransmiter = function () {
			window.parent.location.reload();
			varindex = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
		//树
		var DemoTree = dtree.render({
			elem: "#dataTree",//html中的id值
			type: "all",
			url: MODULE_PATH + 'getAllIRegion',
			method:"get",
			request: {"type":"0"},//传递参数
			initLevel: "2",
			icon:'2',
			firstIconArraylayui:"0",
			checkbar: true,
			checkbarType: "no-all",//显示半选中状态
			scroll:"#organizationTreeContent", // 绑定div元素
			toolbar:true,
			success:function (data) {
			},
			checkbarFun:{
				chooseDone: function(checkbarNodesParam) {//点击复选框的事件
					var datas=dtree.getCheckbarNodesParam("dataTree");
					var data;
					for (let i = 0; i < datas.length; i++) {
						var parentNode = dtree.getParam(DemoTree, datas[i].parentId)
						if(parentNode.checked==1){
						}else{
							$('#regionname').val(datas[i].context);
							$('#region').val(datas[i].nodeId);
						}
					}
				}
			}
		});
	})
</script>
</html>